package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;

import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.web.page.TableDataInfo;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;

import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.TBusSchedule;
import cn.edu.wfit.modules.infomanagement.dto.DriverAndSchedule;
import cn.edu.wfit.modules.infomanagement.service.ITBusScheduleService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 存储每日发车安排Controller
 * 
 * @author zhanghao
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/schedule")
public class TBusScheduleController extends BaseController
{
    @Autowired
    private ITBusScheduleService tBusScheduleService;

    /**
     * 查询存储每日发车安排列表
     */
    @RequiresPermissions("system:schedule:list")
    @GetMapping("/list")
    public TableDataInfo list(TBusSchedule tBusSchedule)
    {
        startPage();
        List<TBusSchedule> list = tBusScheduleService.selectTBusScheduleList(tBusSchedule);
        return getDataTable(list);
    }

    /**
     * 导出存储每日发车安排列表
     */
    @RequiresPermissions("system:schedule:export")
    @Log(title = "存储每日发车安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusSchedule tBusSchedule)
    {
        List<TBusSchedule> list = tBusScheduleService.selectTBusScheduleList(tBusSchedule);
        ExcelUtil<TBusSchedule> util = new ExcelUtil<TBusSchedule>(TBusSchedule.class);
        util.exportExcel(response, list, "存储每日发车安排数据");
    }

    /**
     * 获取存储每日发车安排详细信息
     */
    @RequiresPermissions("system:schedule:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tBusScheduleService.selectTBusScheduleById(id));
    }

    /**
     * 新增存储每日发车安排
     */
    @RequiresPermissions("system:schedule:add")
    @Log(title = "存储每日发车安排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBusSchedule tBusSchedule)
    {
        return toAjax(tBusScheduleService.insertTBusSchedule(tBusSchedule));
    }

    /**
     * 修改存储每日发车安排
     */
    @RequiresPermissions("system:schedule:edit")
    @Log(title = "存储每日发车安排", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBusSchedule tBusSchedule)
    {
        return toAjax(tBusScheduleService.updateTBusSchedule(tBusSchedule));
    }

    /**
     * 删除存储每日发车安排
     */
    @RequiresPermissions("system:schedule:remove")
    @Log(title = "存储每日发车安排", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBusScheduleService.deleteTBusScheduleByIds(ids));
    }

    /**
     * 根据driverId查询发车安排和相关信息
     */
     @RequiresPermissions("system:schedule:query")
    @GetMapping("/driver/{driverId}")
    public AjaxResult getScheduleByDriverId(@PathVariable("driverId") Long driverId)
    {
        List<DriverAndSchedule> list = tBusScheduleService.selectTBusScheduleByDriverId(driverId);
        return success(list);
    }
}
